package com.livepan.server.service.impl;

import com.livepan.server.dao.RecordDOMapper;
import com.livepan.server.dataobject.RecordDO;
import com.livepan.server.dataobject.RecordDOKey;
import com.livepan.server.error.BusinessException;
import com.livepan.server.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RecordServiceImpl implements RecordService {

    @Resource
    private RecordDOMapper recordDOMapper;

    @Override
    public boolean is_down(String userId, int questionId) throws BusinessException {
        return getRecordById(userId, questionId) != null;
    }

    @Override
    public RecordDO getRecordById(String userId, int questionId) throws BusinessException {
        RecordDOKey recordDOKey = new RecordDOKey();
        recordDOKey.setStuId(userId);
        recordDOKey.setQuesId(questionId);
        RecordDO recordDO = recordDOMapper.selectByPrimaryKey(recordDOKey);
        return recordDO;
    }

    @Override
    public boolean is_correct(String userId, int questionId) throws BusinessException {
        return getRecordById(userId, questionId).getIsCorrect();
    }


}
